package org.tisn.qq;

import org.tisn.qq.agr.QQUser;
import org.tisn.qq.net.PortGateFactory;
import org.tisn.qq.service.TQQServer;
import org.tisn.qq.service.TQQServer.MyBinder;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class TQQActivity extends Activity {
	private TextView tv;
	private  Button bt;
	
	private TQQServer QService;
	private static final String TAG = "TQQ";
	
	QQClient client;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        tv = (TextView) findViewById(R.id.textView1 );
        bt = (Button) findViewById(R.id.button1);
        
        OnClickListener l = new OnClickListener(){

			public void onClick(View arg0) {
				if (arg0.equals(bt)) {
					a();
				}
			}};
		bt.setOnClickListener(l);
		((Button) findViewById(R.id.button2)).setOnClickListener(l);
		
		Intent i = new Intent(this, TQQServer.class);
		//this.bindService(i, conn, 5317);
		
		client = new QQClient();
		client.setConnectionPoolFactory(new PortGateFactory());

		QQUser user = new QQUser(1022291914, "shit.5317520");
		client.setUser(user); 
        //client.setLoginServer("211.136.236.66"); 

    }
    private ServiceConnection conn = new ServiceConnection() {

		public void onServiceConnected(ComponentName name, IBinder service) {
			MyBinder binder = (MyBinder)service;
            QService = binder.getService();
		}

		public void onServiceDisconnected(ComponentName name) {
			
		}

    };
    
    private void a() {
    	//QService.qLogin("1022291914", "shit.5317520");
    	client.login();
        
    }

}